package cn.sz.dzy.provider.service.impl;

import cn.hutool.json.JSONUtil;
import cn.sz.dzy.common.enums.StatusCode;
import cn.sz.dzy.common.pojo.FaceRequestObject;
import cn.sz.dzy.common.pojo.ResponseStatusObjectWrapper;
import cn.sz.dzy.provider.service.IFaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @program: gta1400
 * @description:
 * @author: DingZhenYun
 * @create: 2021-12-09 09:44
 **/
@Service
@Slf4j
public class FaceServiceImpl implements IFaceService {

    @Override
    public ResponseEntity<String> faces(FaceRequestObject faceRequestObject) {
        FaceRequestObject.FaceListObject faceListObject = faceRequestObject.getFaceListObject();
        List<FaceRequestObject.Face> faceObject = faceListObject.getFaceObject();
        FaceRequestObject.Face face = faceObject.get(0);//脸信息
        FaceRequestObject.SubImageList subImageList = face.getSubImageList();//包含base64的信息

        //todo 人脸对比之类的一系列操作，待处理
        ResponseStatusObjectWrapper responseStatusObjectWrapper=new ResponseStatusObjectWrapper();
        ResponseStatusObjectWrapper.ResponseStatusObject responseStatusObject = new ResponseStatusObjectWrapper().new ResponseStatusObject();
        responseStatusObject.setId(face.getDeviceID());
        responseStatusObject.setLocalTime(DateTimeFormatter.ofPattern("YYYYMMddHHmmss").format(LocalDateTime.now()));
        try {
            InetAddress address = InetAddress.getLocalHost();
            responseStatusObject.setRequestURL("http:"+address.getHostAddress()+":8111"+"/VIID/Faces");
            responseStatusObject.setStatusCode(StatusCode.OK.getCode());
            responseStatusObject.setStatusString(StatusCode.OK.getName());
            responseStatusObjectWrapper.setResponseStatusObject(responseStatusObject);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String s = JSONUtil.toJsonStr(responseStatusObjectWrapper);
        ResponseEntity responseEntity = new ResponseEntity(JSONUtil.toJsonStr(responseStatusObjectWrapper), HttpStatus.OK);
        return responseEntity;
    }
}
